package org.bot.plugin.data.event;

import com.alibaba.fastjson.JSONArray;
import org.bot.api.event.DataStorage;
import org.bot.api.event.EventName;
import org.bot.api.event.Events;
import org.bot.api.flow.FlowNode;
import org.springframework.stereotype.Component;

/**
 * @Author: 沧月
 * @Date: 2024/7/4 11:05
 * @Description: 描述
 */

@Component
@EventName("数组是否为空")
public class DataArrayIsEmpty implements Events {

    @Override
    public Object exec(FlowNode node, DataStorage data) {
        Object array = data.get(node.getDataIndex());
        if (array instanceof JSONArray) {
            return ((JSONArray) array).isEmpty();
        }
        throw new RuntimeException("对象不为JSONArray数组");
    }
}
